Garbage collection is a mechanism used for memory management in computer systems. Garbage collectors function by reclaiming memory used by objects that are no longer in use by an application or computer system (i.e. garbage). A generational garbage collector relies on the observation that objects often die young (i.e. become garbage shortly after their allocation). Young objects are typically segregated from older objects (i.e. objects that have been alive or in use for a certain number of garbage collections), as this enables the garbage collector to reclaim space from a younger generation (i.e. a set of young objects) at low cost (e.g. collection cost is typically proportional to the number of live objects). A common and effective strategy is to divide heap space in at least two generations—a young generation and an old generation. Objects are allocated in the young generation and mature there until they reach a specific age that makes them candidates for promotion to the old generation. A commonly used aging mechanism consists of counting how many young generation garbage collections an object survives (e.g. by increasing a counter in the object's header). In order to perform a garbage collection of the young generation only, references from the old generation to the young generation need to be tracked. The data structure used to keep track of these cross-generation references is called a remembered set.
Region-based garbage collectors go a step further and decompose the heap into relatively small logical regions of fixed size that can be collected independently so as to limit pause-time and improve responsiveness of applications. Region-based garbage collectors are also better equipped to adjust the effective footprint of applications as they enable the release of backing storage (i.e. main-memory) used by the virtual pages of arbitrary unused regions. Region-based garbage collectors can be combined with generational mechanisms as segregating young from old objects provides an easy way to identify regions with large amounts of garbage. In this case, each generation is made of a set of (potentially non-contiguous) regions. Each region carries a type that indicates what generation the region belong to (e.g. the eden and survivor type of regions belong to the young generation, while old regions belong to the old generation). Region-based garbage collectors are equipped with the necessary remembered set mechanisms to enable collection of one or more regions independently of others. This remembered set can be used as well to trace all live young objects.
The young generation is often collected using a copying mechanism, wherein live objects are evacuated from the young generation to a small maturing space that is part of the young generation. For instance, the young generation may be organized as one large eden space and two small survivor spaces (respectively, the from and to spaces), only one of which is active at a time. Mutator threads may allocate objects directly into the eden space via thread local allocation buffers. A young generation collection evacuates the live objects by copying the live objects from the eden space and the from survivor space to the to survivor space. The evacuated regions are then returned to a pool of free regions. The age of an object is increased as the object is copied to the to survivor space. Objects with an age greater than a tenuring threshold are promoted (i.e. copied) to the old generation. The greater the size of an object, the more memory and resource intensive the promotion (i.e. copying) of the object is.